
#include "GNS_NodeMgr.h"

GNS_NodeMgr* GNS_NodeMgr::_instance = nullptr;

GNS_NodeMgr::GNS_NodeMgr()
{}

GNS_NodeMgr::~GNS_NodeMgr()
{}

GNS_NodeMgr* GNS_NodeMgr::getInstance()
{
	if (_instance == nullptr)
		_instance = new GNS_NodeMgr();
	return _instance;
}

void GNS_NodeMgr::pushMenuNode(std::string strName, Node* menuNode)
{
	_mapMenuNode[strName] = menuNode;
}

Node* GNS_NodeMgr::getMenuNode(std::string strName)
{
	return _mapMenuNode[strName];
}

void GNS_NodeMgr::setMenuVisible(Node* menuNode)
{
	std::map<std::string, Node*>::iterator mapNameIter = _mapMenuNode.begin();
	for (; mapNameIter != _mapMenuNode.end(); ++mapNameIter)
	{
		if (mapNameIter->second != menuNode)
			mapNameIter->second->setVisible(false);
		else
			mapNameIter->second->setVisible(true);
	}
}

void GNS_NodeMgr::setMenuVisible(std::string strName, bool bFlag)
{
	if (_mapMenuNode[strName] != nullptr)
		_mapMenuNode[strName]->setVisible(bFlag);
}

void GNS_NodeMgr::pushChildNode(std::string strName, Node* childNode)
{
	_mapChildNode[strName] = childNode;
}

void GNS_NodeMgr::eraseChildNode(std::string strName)
{
	if (_mapChildNode[strName] != nullptr)
	{
		_mapChildNode[strName]->removeAllChildrenWithCleanup(true);
		_mapChildNode[strName]->removeFromParentAndCleanup(true);
		_mapChildNode.erase(strName);
	}		
}

void GNS_NodeMgr::setChildVisible(std::string strName, bool bFlag)
{
	if (_mapChildNode[strName] != nullptr)
		_mapChildNode[strName]->setVisible(bFlag);
}